/**
	SUNNY Project, Anyang Normal University, IMP-CAS
	\brief This code is for tackling the full configuration interaction
	in many-body problems which is a common question in many-body problems
	\since 2020/01/31
	\date Last modified: 2020/01/31
	\copyright 2020-2022, SUN Yazhou
  \copyright SUNNY project, Anyang Normal University, IMP-CAS
*/

#include <iostream>
#include "TAHPairing.h"
#include "TADiagonalize.h"
#include "TALanczos.h"
#include "TASparseMatrix.h"
#include "TASPStateManager.h"
#include "TAMBSDManager.h"
#include "TAParaManager.h"

using std::cout;
using std::endl;

int main(){
	PARA->SetBaseDir("config/fci");
	TAHPairing *pair = new TAHPairing("ham.yaml");
	TASPStateManager::Instance()->Print();
	TAMBSDManager::Instance()->Print();
	// getchar();

	const int n = int(pair->GetNBasis());
	matrix *H = pair->Matrix(); // the hamiltonian matrix
	cout << "----- The Hamiltonian matrix -----" << endl;
	H->Print();
	// H->PrintInC();
	matrix z(n, n); // the matrix to store the eigenvectors
	TASparseMatrix v; double d[n*2];
	for(int i = 0; i < n*2; i++) d[i] = -9999.;
	// TASparseVec *x = new TASparseVec("x");
	// for(int i = 0; i < 9; i++) x->Fill(i, 1.);
	// double xx[n];
	// for(int i = 0; i < 9; i++) xx[i] = 1.;
	// TALanczos::LanczosPurge(*pair, d, v, x, n);
	// TADiagonalize::LanczosPurge(*H, n, d, z, xx, n);
	TALanczos::PurgeRestart(*pair, d, v, n);
	// TADiagonalize::PurgeRestart(*H, n, d, z, n);

	for(int i = 0; i < n; i++) cout << d[i] << endl;
	v.Print();
	v.PrintInC(n);
	// z.Print();

	v.Save();
	TATreeCol::CloseFile();

	// return 0;

	// cout << "Traditional Diagonalization routines" << endl;
	// H returns the eigenvector matrix, the original H is destroyed
	// TADiagonalize::TridiagQLSort(*H, n, d);
	// H->Print();

	// z returns the eigenvector matrix, H is destroyed
	// TADiagonalize::JacobiSort(*H, n, d, z);
	// for(int i = 0; i < n; i++) cout << d[i] << endl;
	// z.Print();

	return 0;
} // end the main function
